package sc.love.boot.mail;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("mail")
public class MailController {

    @Autowired
    private MailTools mailTools;

    @RequestMapping(value="/send")
    @ResponseBody
    public String send(@RequestBody  String message, HttpServletRequest request) {
        JSONObject jsonObject = JSONObject.parseObject(message);
        String from = jsonObject.getString("from");
        String to = jsonObject.getString("to");
        String topic = jsonObject.getString("topic");
        String text = jsonObject.getString("text");
        String send = mailTools.send(topic, text, from, to);
        return send;
    }
}
